import { Component, OnInit } from '@angular/core'
import { FormBuilder, FormGroup } from '@angular/forms'
import { Location } from '@angular/common'
import { ApiService } from '../../services/api.service'
import { ModalService } from '@shared/utils'
import { PageService } from '@core/http'
import { QlMessageService } from 'qloud-angular/package/message/message.service'
import { Router } from '@angular/router'
import { ModalConfirmComponent } from '@app/shared/components/modal-confirm/modal-confirm.component'
import { CursorService } from '@app/core/http/cursor.service'

@Component({
  selector: 'app-finanical-combo',
  templateUrl: './finanical-combo.component.html',
  styleUrls: ['./finanical-combo.component.scss'],
  providers: [ModalService, PageService]
})
export class FinanicalComboComponent implements OnInit {
  public productList: any[] = []
  public showGroup = false
  public formGroup: FormGroup
  public queryParams: any = ''
  // = this.fb.group({
  //   target: [''],
  //   period: [''],
  //   assumption: this.fb.group({ start: [''], end: [''] }),
  //   riskLevel: [''],
  //   customerStars: [''],
  //   aum: ['500000.00'],
  //   debt: ['900000,00']
  // })
  constructor(
    public cursorService: CursorService,
    public location: Location,
    private apiService: ApiService,
    private fb: FormBuilder,
    public modal: ModalService,
    public pageService: PageService,
    private message: QlMessageService,
    private router: Router
  ) {
    this.formGroup = fb.group({
      investAimCode:[null],
      productPeriodicity: [null],
      riskLevelCode:[null],
      custAum:[null],
      custDebt:[null],
      productPredictProfitFloor:[null],
      productPredictProfitCelling:[null],
  })
  }

  ngOnInit() {
    // this.reflashData();
  }

  public onCheckChange(selection) {
    this.showGroup = selection.length > 0
  }

  public onRefresh() {
    this.reflashData()
  }

  public reflashData() {
    this.queryParams = {
      index: 0,
      size: 10,
      investAimCode:this.formGroup.value.investAimCode,
      productPeriodicity:this.formGroup.value.productPeriodicity,
      riskLevelCode:this.formGroup.value.riskLevelCode,
      custAum:this.formGroup.value.custAum,
      custDebt:this.formGroup.value.custDebt,
      productPredictProfitFloor:this.formGroup.value.productPredictProfitFloor,
      productPredictProfitCelling:this.formGroup.value.productPredictProfitCelling,
    }
    this.apiService.getrecommondProduct().subscribe(data => {
      this.productList = data
      console.log(JSON.stringify(data, null, 4))
    })
  }
  /**
   * 删除推荐产品
   */
  public delRecommonProduct(ref: any) {
    this.modal
      .open({
        title: '确认删除',
        component: ModalConfirmComponent
      })
      .subscribe(() => {
        this.apiService.delrecommondProduct(ref.rowData.id).subscribe(data => {
          // this.message.success(data[0].retMsg)
        })
      })
  }
}
